package 算法.leetcode.labuladong.数组和链表;

import java.util.Stack;

/**
 * @author lchenglong
 * @date 2022/6/20
 */
public class 股票价格跨度 {
    class StockSpanner {
        // int[]{股票价格，跨度}
        Stack<int[]> stk = new Stack<>();
        public StockSpanner() {

        }

        public int next(int price) {
            // 算上当天的
            int count = 1;
            while(!stk.isEmpty()&&price>=stk.peek()[0]){
                int[] prev = stk.pop();
                count += prev[1];
            }
            stk.push(new int[]{price,count});
            return count;
        }
    }
}
